<cfcomponent extends="net.sourceforge.cfunit.framework.TestCase">


  <cffunction name="setUp" returntype="void" access="public">
			<cfset serviceDefinitionLocation = expandPath( 'services.xml' ) />
			<cfset coldSpring = createObject( 'component', 'coldspring.beans.DefaultXmlBeanFactory').init() />
			<cfset coldSpring.loadBeansFromXmlFile("/actionpacks/cfsvn/config/cs/svnConfiguration.xml") />
      <cfset variables.cfSvnFckFacade = coldSpring.getBean('cfSvnFckFacade') />
   </cffunction>


	<cffunction name="verifyRevisionInfo" returntype="string" access="private">
		<cfargument name="revisioninfo">
		<cfif (left(revisioninfo,1) eq "r")>
		  <cfreturn "revised">
		<cfelse>
			<cfreturn revisioninfo>
		</cfif>
	</cffunction>

	<cffunction name="testGetFolders" access="public" returntype="any" hint="runs an fck command.">
		<cfset var xmlResp = variables.cfSvnFckFacade.getFolders("/")>
		<cfset assertEquals(expected="tempfile.txt",actual=xmlResp) />
	</cffunction>

	<cffunction name="testGetFoldersAndFiles" access="public" returntype="any" hint="runs an fck command.">
		<cfset var xmlResp = variables.cfSvnFckFacade.getFoldersAndFiles("/")>
		<cfset assertEquals(expected="tempfile.txt",actual=xmlResp) />
	</cffunction>

	<cffunction name="testCreateFolder" access="public" returntype="any" hint="runs an fck command.">
		<cfset var currentFolder = "/">
		<cfset var newFolderName = "testfolder">
		<cfset var commitMessage = "testing adding a new folder">
	  <cfset var resp = variables.cfSvnFckFacade.createFolder(currentFolder,NewFolderName,commitMessage)>
	  <cfset var xmlResp = xmlParse(resp)>
	  <cfset var errorNumber = xmlResp["connector"]["error"]["XmlAttributes"]["number"]>
		<cfset assertEquals(expected="0",actual=errorNumber) />
	</cffunction>

	<cffunction name="testCreateFile" access="public" returntype="any" hint="runs an fck command.">
		<cfset var resp = variables.cfSvnFckFacade.createFile("/","test.txt","testing fckfacade create file")>
	  <cfset var xmlResp = xmlParse(resp)>
	  <cfset var errorNumber = xmlResp["connector"]["error"]["XmlAttributes"]["number"]>
		<cfset assertEquals(expected="0",actual=errorNumber) />
	</cffunction>

	<cffunction name="testThumbnail" access="public" returntype="any" hint="tests thumbnail capability.">
		http://prek.dev.local/?event=repo.fckConnector&Command=thumbnail&Type=Image&ExtraParams=&CurrentFolder=/pages/sites/achildsgarden/images&filename=Dance_Bear.gif
	</cffunction>

	<cffunction name="runFckCommand" access="public" returntype="any" hint="runs an fck command.">
	  <cfargument name="event" type="any">
	  <cfset var command = arguments.event.getValue("command","/")>
	  <cfset var currentFolder = arguments.event.getValue("CurrentFolder","/")>
	  <cfset var type = arguments.event.getValue("type")>
	  <cfset var svnFacade = getCFSvnFckFacade()>
	  <cfset var xmlResp = "">
	  <cfswitch expression="#command#">
		  <cfcase value="getFolders">
			  <cfset xmlResp = svnFacade.getFolders(currentFolder)>
			</cfcase>
		  <cfcase value="getFoldersAndFiles">
			  <cfset xmlResp = svnFacade.getFoldersAndFiles(currentFolder)>
			</cfcase>
		  <cfcase value="CreateFolder">
			  <cfset xmlResp = svnFacade.createFolder(currentFolder,arguments.event.getValue("NewFolderName"),arguments.event.getValue("commitMessage"))>
			</cfcase>
		  <cfcase value="CreateFile">
			  <cfset xmlResp = svnFacade.createFile(currentFolder,arguments.event.getValue("NewFileName"),arguments.event.getValue("commitMessage"))>
			</cfcase>
		  <cfcase value="Thumbnail">
			  <cfset xmlResp = svnFacade.thumbnail(currentFolder,arguments.event.getValue("FileName"))>
			</cfcase>
		  <cfcase value="FileUpload">
			  <cfset xmlResp = svnFacade.fileupload(currentFolder,"NewFile",arguments.event.getValue("commitMessage"))>
			</cfcase>
		  <cfcase value="GetUploadProgress">
			  <cfset xmlResp = svnFacade.GetUploadProgress(currentFolder,type)>
			</cfcase>
			
		</cfswitch>
	  <cfset arguments.event.setValue("xmlcontent",xmlResp)>
	</cffunction>
			
</cfcomponent>